<html>
<head><meta charset="utf-8"><title>Support for #[cfg(test)] · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html">Support for #[cfg(test)]</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="206230292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206230292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thiébaud Weksteen <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206230292">(Aug 07 2020 at 07:26)</a>:</h4>
<p>I've noticed that r-a was not resolving names when inside a tests mod (that is, preceded with the attribute #[cfg(test)]). This is for a rust-project.json type project. This can be fixed by adding "test" to the cfg attribute but I've noticed that many projects uses this as a fake/mocking mechanism (with #[cfg(not(test))] for the real module). In this case, we would lose the analysis of the real module.<br>
Is there anything I'm missing here? Is there any solution to have both parsed?</p>



<a name="206440712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206440712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thiébaud Weksteen <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206440712">(Aug 10 2020 at 09:04)</a>:</h4>
<p><span class="user-mention" data-user-id="116114">@Paul Faria</span> , you've submitted <a href="https://github.com/rust-analyzer/rust-analyzer/pull/4784/commits/9c35f135b9c872e904ee1e838cfa69fc5745c45f#diff-1c8e6b45624e6ce512961af52e9a1aa3R396">https://github.com/rust-analyzer/rust-analyzer/pull/4784/commits/9c35f135b9c872e904ee1e838cfa69fc5745c45f#diff-1c8e6b45624e6ce512961af52e9a1aa3R396</a> which explicitly adds "test" cfg. Any input on my question?</p>



<a name="206451026"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206451026" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206451026">(Aug 10 2020 at 11:33)</a>:</h4>
<p>As I understand it, this isn't currently possible. It would break goto def functionality (which item do you route to?). It would also not be clear what functionality is available. What happens when the types, functions or fields conflict with each other?</p>
<p>I had proposed configuring cfg items with some kind of UI, and <span class="user-mention" data-user-id="133169">@matklad</span> had brought up an example of a checkbox UI that could appear on Cargo.toml files. Basically having the ability to toggle the features on and off.</p>
<p>I've definitely run into your issue before in my own crates and at work, so I understand the frustration. I could also be wrong, and the above might be possible, but I don't have enough experience with all the details to say for sure.</p>



<a name="206453692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206453692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206453692">(Aug 10 2020 at 12:15)</a>:</h4>
<p>it is kind of possible, functionality like goto def is already built with this in mind. We can have multiple configurations of a crate in the crate graph, and a file can belong to any number of them. Actually implementing that would probably not be completely trivial anyway though, and would have a performance impact since we'd have to do a lot of analysis twice.</p>



<a name="206453857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206453857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206453857">(Aug 10 2020 at 12:18)</a>:</h4>
<p>it would be interesting to experiment with though</p>



<a name="206454401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206454401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206454401">(Aug 10 2020 at 12:24)</a>:</h4>
<p>(basically, the way it works for e.g. goto def all goes back to <a href="https://github.com/rust-analyzer/rust-analyzer/blob/f3336509e52187a7a70a8043557a7317872e3a2f/crates/ra_hir/src/semantics/source_to_def.rs#L32-L38">this</a>, where it tries to find a crate that actually contains the file. I'm not 100% sure it'll deal well with the case where the crate contains the file, but the actual code we're interested in is cfg'd out though)</p>



<a name="206457904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206457904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206457904">(Aug 10 2020 at 13:06)</a>:</h4>
<p>TIL. I assume this means we'd need to keep track of two trees? One with test on and one off? If not, how would it interact with chalk (I assume that's what's used to do the type analysis, I've never delved that deep into the RA codebase before).</p>



<a name="206459142"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206459142" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206459142">(Aug 10 2020 at 13:19)</a>:</h4>
<p>it's really just like two different crates in the crate graph, that happen to share files</p>



<a name="206459171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206459171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206459171">(Aug 10 2020 at 13:19)</a>:</h4>
<p>all the HIR is completely separate and duplicated</p>



<a name="206462427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206462427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206462427">(Aug 10 2020 at 13:51)</a>:</h4>
<p>Assuming we get this working, what if, as a way of mitigating performance issues, this is a feature that's defaulted off and only turned on through settings?</p>



<a name="206462800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206462800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206462800">(Aug 10 2020 at 13:54)</a>:</h4>
<p>as a first step at least, probably</p>



<a name="206547591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206547591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thiébaud Weksteen <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206547591">(Aug 11 2020 at 07:35)</a>:</h4>
<p>Thanks, I'll add this info to an issue on github so this can be tracked.</p>



<a name="206764100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206764100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206764100">(Aug 12 2020 at 23:12)</a>:</h4>
<p><span class="user-mention silent" data-user-id="129457">Florian Diebold</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Support.20for.20.23.5Bcfg(test).5D/near/206459142">said</a>:</p>
<blockquote>
<p>it's really just like two different crates in the crate graph, that happen to share files</p>
</blockquote>
<p>This is actually how we're currently generating our <code>rust-project.json</code>, because I haven't worked on deduplication, yet.  And for now "first one wins" seems to be the behavior.</p>



<a name="206764310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206764310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206764310">(Aug 12 2020 at 23:15)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116114">Paul Faria</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Support.20for.20.23.5Bcfg(test).5D/near/206451026">said</a>:</p>
<blockquote>
<p>As I understand it, this isn't currently possible. It would break goto def functionality (which item do you route to?). It would also not be clear what functionality is available. What happens when the types, functions or fields conflict with each other?</p>
<p>I had proposed configuring cfg items with some kind of UI, and <span class="user-mention silent" data-user-id="133169">matklad</span> had brought up an example of a checkbox UI that could appear on Cargo.toml files. Basically having the ability to toggle the features on and off.</p>
<p>I've definitely run into your issue before in my own crates and at work, so I understand the frustration. I could also be wrong, and the above might be possible, but I don't have enough experience with all the details to say for sure.</p>
</blockquote>
<p>I wonder how difficult it would be to wire up a "config-switcher" that just reloaded rust-analyzer after switching cfgs?  (so you could switch between cfgs, and then just kick off a re-start of the language server for the workspace).  Seems like it could be implemented in the VSCode extension itself, maybe?</p>



<a name="206813191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206813191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206813191">(Aug 13 2020 at 13:17)</a>:</h4>
<p>I was actually wondering if we could tie it into the lookup logic Florian shared above. Rather than just passing in a FileId, we could pass in a FileId and a filtering callback of some kind. Like, if there are multiple options, then use the callback to filter down and then if there are still options, fallback to a single value. I'm not sure how complicated it would be to thread that callback through to that code though. And Florian did mention this would cause perf issues. I think I'll experiment with something on the side there.</p>



<a name="206813464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206813464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206813464">(Aug 13 2020 at 13:20)</a>:</h4>
<p>I think it's more that the lookup logic needs to be able to deal with the possibility that the container exists in a certain crate, but the child that we actually want doesn't, and then we need to try the next crate</p>



<a name="206813486"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206813486" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206813486">(Aug 13 2020 at 13:20)</a>:</h4>
<p>but the config switcher thing has also been talked about and is probably the easier short-term solution</p>



<a name="206813523"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/206813523" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#206813523">(Aug 13 2020 at 13:21)</a>:</h4>
<p>ok, I'll focus on that then</p>



<a name="212042834"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/212042834" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thiébaud Weksteen <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#212042834">(Oct 02 2020 at 07:52)</a>:</h4>
<p>Apologies for the delay in creating that bug. Here it is: <a href="https://github.com/rust-analyzer/rust-analyzer/issues/6117">https://github.com/rust-analyzer/rust-analyzer/issues/6117</a></p>



<a name="213918560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/213918560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#213918560">(Oct 20 2020 at 13:29)</a>:</h4>
<p>Now that I'm back from vacation, I've had time to work on this a bit more. I'm currently able to keep track of the configurations on the initialization with cargo.toml projects (rust-project.json will be done soon too), and I've found the spot to properly load the configurations at <a href="https://github.com/rust-analyzer/rust-analyzer/blob/be762ccccd5a86632e60351518528d078785a3e2/crates/hir/src/semantics/source_to_def.rs#L32">https://github.com/rust-analyzer/rust-analyzer/blob/be762ccccd5a86632e60351518528d078785a3e2/crates/hir/src/semantics/source_to_def.rs#L32</a></p>
<p>My idea to connect the two is to add a method available on the db such that I can filter like so:</p>
<div class="codehilite"><pre><span></span><code>            .filter(|&amp;&amp;crate_id| self.db.config_active_for(crate_id))
</code></pre></div>


<p>In between the iter and the find_map linked above.</p>
<p>My thought was that this makes the most sense on the <code>FileLoader</code> trait: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/be762ccccd5a86632e60351518528d078785a3e2/crates/base_db/src/lib.rs#L91">https://github.com/rust-analyzer/rust-analyzer/blob/be762ccccd5a86632e60351518528d078785a3e2/crates/base_db/src/lib.rs#L91</a>, but it wasn't clear to me how I would keep this up to date or populate this from <code>CrateData</code> (where I'm currently storing the available features from cargo.toml). <span class="user-mention" data-user-id="133169">@matklad</span> any ideas on how I should approach this, or am I possibly starting at the wrong place?</p>



<a name="213937441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/213937441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#213937441">(Oct 20 2020 at 15:39)</a>:</h4>
<p>I don't think we should add callbacks for configuation</p>



<a name="213937570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/213937570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#213937570">(Oct 20 2020 at 15:40)</a>:</h4>
<p>We need to expose the API that iterates all possible candidates, instead of returning the first one, and select the approriate candidate higher in the stack, in the ide layer</p>



<a name="213954980"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/213954980" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#213954980">(Oct 20 2020 at 17:45)</a>:</h4>
<p>Ok, I'll give that a shot after work today.</p>



<a name="214321572"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/214321572" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#214321572">(Oct 23 2020 at 14:37)</a>:</h4>
<p>So I feel like I may have been taking the wrong approach again. I modified the approach to return a vec of matching modules, and have started bubbling that up (I tried returning impl iterator but the usage of self within the functions causes issues due to borrowing self mutably and immutably at the same time. There might be workarounds available). The issue is there's a lot of code within the various layers that assume there's only 0 or 1 modules, and then maps that data to other types. I've gotten to the point where now even multiple source analyzers are being generated since it's not clear which ids to pass to those. I feel like bubbling that complexity up might make sense if there was a way to filter which analysis to perform, but with vecs, this is causing a ton of unused information to be processed, on top of making the code higher up the stack harder to follow.</p>



<a name="214439652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/214439652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#214439652">(Oct 24 2020 at 17:39)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> I wonder if I misunderstood your original suggestion. Were you implying that I should modify <code>RootDabase</code> (in the <code>ide_db</code> crate) so that when its <code>&lt;impl FileLoader for RootDabase&gt;::relevant_crates</code> is called, the filtering is done within that fn? I've tried to continue with the exposing the <code>Vec&lt;Module&gt;</code> up the call stack (rather than returning the first result from <code>source_to_def.rs:SourceToDefCtx::file_to_def</code>, but it just touches so much that it really feels like the wrong approach. Let me know if you have time this weekend or early in the morning (I'm in Eastern US) to go over things.</p>



<a name="214558601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/214558601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#214558601">(Oct 26 2020 at 10:49)</a>:</h4>
<p>No, I do feel that "just return a list of things and kick the can up to the caller to select one" is a fundamentally better approach than "has some global config for selection".</p>
<p>But I think some engineering should be applied to minimize the syntactic overhead of threading this information. Infecting everything with a new viral monad (list) is indeed problematic. Generally, when you want to thread something somewhere, it's better to piggyback on some existing piece of context, which already is threaded everywhere.</p>
<p>I think for rust-analyzer the appropriate context is the Semantics. Currently it is created with <code>pub fn new(db: &amp;DB) -&gt; Semantics&lt;DB&gt;</code>, and just from this signature it is obvious that it is agnostic about current set of CFG (well, unless we put some global current context in DB, which is the reason why we should avoid doing that)</p>
<p>I think we should add <code>pub fn new_for_crate(db: &amp;DB, krate: CrateId) -&gt; Semantics&lt;DB&gt;</code> to allow creating semantics scoped to the current crate.<br>
Then, somewhere in the IDE, we should have a function that returns a list of applicable <code>CrateId</code> and the one that matches best. I am not sure what that would look like exactly, in theory it should be able to do tricks like (pick the crate with test if cursor is inside tests).  After that, we can incrementally start substituting<code>Semantics::new_for_crate</code> for <code>Semantics::new</code>. When there are no crate-less usages left, we can delete thouse.</p>



<a name="214576330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/214576330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#214576330">(Oct 26 2020 at 13:58)</a>:</h4>
<p>I played around with your idea of storing the <code>CrateId</code> inside of <code>Semantics</code> and it really simplifies a lot of the changes. I think in the ide layer I'll just need a way to call <code>db.relevant_crates(file_id)</code> and use that to filter by configs before creating a <code>Semantics</code>. This was incredibly helpful! I'll try some more things out after work.</p>



<a name="215325291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/215325291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#215325291">(Nov 02 2020 at 14:30)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> where is the best place to store the currently active crate for the current file? For example, with rust-project.json, we can have two crates, one with test enabled, and one with it disabled, that both include <a href="http://some_file.rs">some_file.rs</a> in its list of files. Where's the best place to store that crate id so that when I do something like goto_definition, I can refer to that crate id so I know which definitions to analyze? Does <code>GlobalState</code> make sense, or does the lsp not necessarily notify the server of when the active file has changed, so there might be a risk of the context being out of sync with the UI?</p>



<a name="215528822"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/215528822" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#215528822">(Nov 04 2020 at 00:34)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116114">Paul Faria</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Support.20for.20.23.5Bcfg(test).5D/near/215325291">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="133169">matklad</span> where is the best place to store the currently active crate for the current file? For example, with rust-project.json, we can have two crates, one with test enabled, and one with it disabled, that both include <a href="http://some_file.rs">some_file.rs</a> in its list of files.</p>
</blockquote>
<p>Should those really be separate crates?  Or just separate instances of the same crate in the crate graph? (or does that really mean the same thing, as I haven't dug deeply into the crate graph after it's created).</p>



<a name="215597907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/215597907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#215597907">(Nov 04 2020 at 15:36)</a>:</h4>
<p>Maybe we could add a field to rust-project.json to say whether <code>test</code> is configurable or not and collapse the two?<br>
Though there still might be cases where one file is included in multiple crates. There's currently nothing that prevents that with the rust-project.json format.</p>



<a name="215611451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/215611451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#215611451">(Nov 04 2020 at 17:05)</a>:</h4>
<blockquote>
<p>where is the best place to store the currently active crate for the current file? F</p>
</blockquote>
<p>Well, the best choice is not to store this at all, but rather pass in as an argument with every request</p>



<a name="215611500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/215611500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#215611500">(Nov 04 2020 at 17:05)</a>:</h4>
<p>Noteice how things like <code>CompletionConfig</code> are arguments, rather then some global state</p>



<a name="215611578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/215611578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#215611578">(Nov 04 2020 at 17:06)</a>:</h4>
<p>So I don't think we should add any state</p>



<a name="215611652"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/215611652" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#215611652">(Nov 04 2020 at 17:06)</a>:</h4>
<p>other than that, stuffing the required info in the <code>Config</code> struct (in rust-analyzer), and materializing the low-level config during requests seems like a good approach</p>



<a name="215664395"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/215664395" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#215664395">(Nov 05 2020 at 02:08)</a>:</h4>
<p>I'm actually debugging something related to this at the moment:  If multiple crates in a rust-project.json contain the same file, what would change _which_ of those crates is found to be the right one?  (we've determined that adding/removing a _different_ crate from the file will cause the <code>test</code> vs. <code>rlib</code> crate to be used for a given source file, and are very confused).</p>



<a name="215832230"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/215832230" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#215832230">(Nov 06 2020 at 11:15)</a>:</h4>
<blockquote>
<p>what would change _which_ of those crates is found to be the right one? </p>
</blockquote>
<p>The relative ordering. I <em>think</em> we are not using any hashsets on the path there, so probably "first one in projec.json wins" works, though I am not entirely sure</p>



<a name="215875437"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/215875437" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#215875437">(Nov 06 2020 at 17:11)</a>:</h4>
<p>Part of the mapping from file id to module id goes through <code>fn relevant_crates(&amp;self, file_id: FileId) -&gt; Arc&lt;FxHashSet&lt;CrateId&gt;&gt;</code>. I think this is where the ordering won't be guaranteed.</p>



<a name="215875583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/215875583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#215875583">(Nov 06 2020 at 17:12)</a>:</h4>
<p>Right!</p>



<a name="215875623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/215875623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#215875623">(Nov 06 2020 at 17:13)</a>:</h4>
<p>Argh, I think we actually should change that back to a Vec</p>



<a name="215875820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/215875820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#215875820">(Nov 06 2020 at 17:14)</a>:</h4>
<p>Also, I should be on top of this more next week. This week has been a bit distracting to say the least.</p>



<a name="216290155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/216290155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> woody77 <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#216290155">(Nov 10 2020 at 23:40)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116114">Paul Faria</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Support.20for.20.23.5Bcfg(test).5D/near/215875437">said</a>:</p>
<blockquote>
<p>Part of the mapping from file id to module id goes through <code>fn relevant_crates(&amp;self, file_id: FileId) -&gt; Arc&lt;FxHashSet&lt;CrateId&gt;&gt;</code>. I think this is where the ordering won't be guaranteed.</p>
</blockquote>
<p>I found that, tracing through code, but wasn't sure how one other crate being added/removed would cause a hashset to change iteration order, unless it _also_ hit a threshold which caused more/less buckets to be used, thereby reshuffling across a larger/smaller set of buckets than before.</p>



<a name="216487604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/216487604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#216487604">(Nov 12 2020 at 15:59)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133169">matklad</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Support.20for.20.23.5Bcfg(test).5D/near/215611500">said</a>:</p>
<blockquote>
<p>Noteice how things like <code>CompletionConfig</code> are arguments, rather then some global state</p>
</blockquote>
<p><span class="user-mention" data-user-id="133169">@matklad</span>  I just got some time this week to jump back. I think I was originally confused by this because <code>CompletionConfig</code> and <code>Config</code> are kept in a struct called <code>GlobalState</code>.  My intention was to keep track of the last known active crate for a file somwhere in <code>GlobalState</code>, but doesn't keeping in <code>Config</code> mean that I can't actively update the currently active crate for a file? For example, looking at how <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/rust-analyzer/src/handlers.rs#L399">https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/rust-analyzer/src/handlers.rs#L399</a> works, the current design doesn't really have a way to notify <code>GlobalState</code> or <code>Config</code> the crate context of the file that will be navigated to. Or maybe I'm misreading your original intent. Would your idea be to store the crate and file associations on initialization and not allow any changes without a full refresh?</p>



<a name="216618912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/216618912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#216618912">(Nov 13 2020 at 14:34)</a>:</h4>
<p>Why do you need to track last active thing? Why this can't be stateless?</p>



<a name="216619189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/216619189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#216619189">(Nov 13 2020 at 14:36)</a>:</h4>
<p>SO, for <code>goto_definition</code>, we should change <code>snap.analysis.goto_definition(position)</code> to <code>snap.analysis.goto_definition(position, goto_definition_config)</code>, where <code>goto_definition_config</code> is a struct contain information about how to bias crates which contain the current file</p>



<a name="216619377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/216619377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#216619377">(Nov 13 2020 at 14:38)</a>:</h4>
<p>It could probably look like this:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">GotoDefConfig</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="c1">// If gotodef request can be resolved in the context of several crates, bias towards the crates from this set</span>
<span class="w">    </span><span class="n">priority_crates</span>: <span class="nc">FxHashSet</span><span class="o">&lt;</span><span class="n">CrateId</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="216629699"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/216629699" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#216629699">(Nov 13 2020 at 15:50)</a>:</h4>
<p>In the process of trying to come up with an example, I found that (at least in the small example) rust-analyzer was already doing what I was trying to make it do. I'm very clearly missing something in my mental model. I had a crate (let's call it Z) with two features, a and b. I had two other crates (use_a and use_b) the each depended on Z with a different feature enabled. They are in different directories, but I included them in the same vs code workspace. When navigating from use_a to Z, once I'm in Z,  it will always act as if only feature a is enabled. When navigating from use_b to Z, once I'm in Z, it will alwasy act as if only feature b is enabled. How/where is the information about the current feature being stored? From what I can see, only the file name is being passed through lsp, so I can't understand how the context is being managed.</p>



<a name="216630191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/216630191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#216630191">(Nov 13 2020 at 15:53)</a>:</h4>
<p>are you opening the whole workspace, or only the respective use crates? If the letter, then the difference is in what <code>cargo metadata</code>output looks liek</p>



<a name="216630844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/216630844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#216630844">(Nov 13 2020 at 15:57)</a>:</h4>
<p>I don't have a cargo workspace, but a vs code workspace (where both crates are opened as individual directories within VS Code, done through the File -&gt; Add Folder to Workspace menu option)</p>



<a name="216631831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/216631831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#216631831">(Nov 13 2020 at 16:03)</a>:</h4>
<p>yeah, i think in this case we"ll call metadata twice, with two different current_dirs, so cargo would enable two sets of flags for us</p>



<a name="216632670"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/216632670" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#216632670">(Nov 13 2020 at 16:08)</a>:</h4>
<p>Though what level is tracking which feature set is currently active for some given file path? I think that's what I've been struggling to figure out. At least, the impression I get is that going from one of the use_* crates to Z maintains the feature set while navigating around Z. Does manually viewing one of the files in use_a or use_b switch the overall context somehow?</p>



<a name="216632712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/216632712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#216632712">(Nov 13 2020 at 16:09)</a>:</h4>
<p>And by manually viewing I mean selecting the file from the file list in VS Code.</p>



<a name="216634083"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/216634083" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#216634083">(Nov 13 2020 at 16:17)</a>:</h4>
<p>Hm, there shouldnt the the "maintinig view" effect. Maybe there are separate instances of rust-analyzer involved somehow?</p>



<a name="216634110"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/216634110" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#216634110">(Nov 13 2020 at 16:17)</a>:</h4>
<p>Maybe it's actually two separate analyses and switching the active file changes which analysis is active?</p>



<a name="216634281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/216634281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#216634281">(Nov 13 2020 at 16:18)</a>:</h4>
<p>I'll take some time to review how that works with the workspaces setup. I'm guessing this is not the same as setting a root project when opening <code>rust-project.json</code> files, right? I.e. those all share the same analysis, it's not separate analyses?</p>



<a name="216634826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/216634826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#216634826">(Nov 13 2020 at 16:22)</a>:</h4>
<p>Well, there <em>should</em> be separate analysis anywhere</p>



<a name="216634838"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/216634838" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#216634838">(Nov 13 2020 at 16:22)</a>:</h4>
<p>If that happens, that is a bug</p>



<a name="216634869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Support%20for%20%23%5Bcfg%28test%29%5D/near/216634869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Support.20for.20.23.5Bcfg(test).5D.html#216634869">(Nov 13 2020 at 16:22)</a>:</h4>
<p>But it looks like we get those...</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>